﻿@include "Eswat.Samples.SampleComponentLibrary.dll"

@using Eswat.Services.WebDriver
@using OpenQA.Selenium
@using Eswat.Samples.SampleComponentLibrary

@{
	var verify = Services.Verify;

	// ---------------------------------------------------------------
	//  TEST EXTERNAL .NET COMPONENT (.dll)
	// ---------------------------------------------------------------

	//// create new component
	var comp = new SampleComponent();
	//#set and verify the title
	comp.Title = "hello component world!";
	verify.AreEqual("hello component world!", comp.Title, "sample component title should match");

	// ---------------------------------------------------------------
	//  TEST WEBSITE
	// ---------------------------------------------------------------
	
	// alias ESWAT web test service for shorter reference
	var web = Services.Web;

	try
	{
		// open IE and go to project "silk"
		web.open("IE");
		web.go("http://localhost:61614/Auth/SignOut"); // always start at sign-out page to ensure we don't resume a previously logged-in session

		// get current bg color
		var originalBG = web.js("return document.body.style.backgroundColor;");
		// set new bg color and return it
		var newBG = web.js("return (document.body.style.backgroundColor = \"#FF0000\");");
		// verify new bg color was set
		verify.AreEqual("#FF0000", newBG, "bg color");
		// restore original bg color
		web.js("document.body.style.backgroundColor = \"" + originalBG + "\"");

		// verify page title
		verify.AreEqual("Mileage Stats | Know where your gas takes you", web.pageTitle, "Silk landing page title should match");
		// verify html.head.title
		verify.AreEqual("Mileage Stats | Know where your gas takes you", web.title.text, "Silk landing title should match");

		// verify <h1> text using Selenium's "By" syntax
		verify.AreEqual("Sign In / Register", web.find(By.TagName("h1")).text, "h1 text");

		// test images shortcut
		verify.AreEqual(6, web.images.Count, "silk images");
		// test byId shortcut
		verify.IsNotNull(web.byId("pinnedSiteContainer"), "silk by id");
		// test oneById shortcut
		verify.IsNotNull(web.oneById("pinnedSiteContainer"), "silk one by id");
		// test allByTag shortcut
		verify.AreEqual(6, web.allByTag("img").Count, "silk images all by tag");
		// test allByClass shortcut
		verify.AreEqual(2, web.allByClass("button").Count, "silk all by class name");
		// test oneByName shortcut
		verify.IsNotNull(web.oneByName("providerUrl"), "silk by name");
		// test attr shortcut
		var providerUrl = web.oneByName("providerUrl");
		var originalProvider = providerUrl.attr("value");
		verify.AreEqual("http://oturner.myidprovider.org/", originalProvider, "silk attribute");
		// test type shortcut
		providerUrl.type("ironruby.net");
		verify.AreEqual("ironruby.net", providerUrl.attr("value"), "silk type text");
		providerUrl.type(originalProvider);
		// test submit shortcut
		providerUrl.submit();

		// test navigation result (next page)
		verify.AreEqual("Mock Authentication", web.pageTitle, "Silk login title should match");
		web.byId("claimed_identifier").submit();

		// test another navigation result (next page)
		verify.AreEqual("Dashboard", web.pageTitle, "Silk login title should match");
		verify.AreEqual("Sample User", web.byId("welcome").oneByTag("span").text, "welcome name");
		var nav = web.oneByClass("nav").allByTag("a");
		// test properties of all...() shortcut result
		verify.AreEqual(4, nav.Count, "nav count");
		verify.AreEqual("Dashboard", nav[0].text, "nav dashboard");
		verify.AreEqual("Charts", nav[1].text, "nav charts");
		verify.AreEqual("Profile", nav[2].text, "nav profile");
		verify.AreEqual("Sign Out", nav[3].text, "nav sign out");
		// test oneByPartialLinkText shortcut (actual link text is "+ Add Vehicle"
		verify.IsNotNull(web.oneByPartialLinkText("Add Vehicle"), "oneByPartialLinkText");
		// test oneByLinkText shortcut
		verify.IsNotNull(web.oneByLinkText("+ Add Vehicle"), "oneByLinkText");

		web.go("http://localhost:61614/Auth/SignOut");
	}
	finally {
		// quit (close IE)
		web.quit();
	}

	// ---------------------------------------------------------------
	//  TEST "verify" API
	// ---------------------------------------------------------------

	verify.True(true);
	verify.True(true, "True(True) should succeed");
	verify.True(true, "True({0}) should succeed", "True");
	verify.True(false, "True(False) should fail");

	verify.IsTrue(true);
	verify.IsTrue(true, "IsTrue(True) should succeed");
	verify.IsTrue(true, "IsTrue({0}) should succeed", "True");
	verify.IsTrue(false, "IsTrue(False) should fail");

	verify.False(false);
	verify.False(false, "False(False) should succeed");
	verify.False(false, "False({0}) should succeed", "False");
	verify.False(true, "False(True) should fail");

	verify.IsFalse(false);
	verify.IsFalse(false, "IsFalse(False) should succeed");
	verify.IsFalse(false, "IsFalse({0}) should succeed", "False");
	verify.IsFalse(true, "IsFalse(True) should fail");

	// bool
	verify.AreEqual(true, true);
	verify.AreEqual(true, true, "AreEqual(True, True) should succeed");
	verify.AreEqual(true, true, "AreEqual({0}) should succeed", "True, True");
	verify.AreEqual(true, false, "AreEqual(True, False) should fail");

	// float
	verify.AreEqual(0f, 0f);
	verify.AreEqual(0f, 0f, "AreEqual(0f, 0f) should succeed");
	verify.AreEqual(0f, 0f, "AreEqual({0}) should succeed", "0f, 0f");
	verify.AreEqual(0f, 1f, "AreEqual(0f, 1f) should fail");

	// double
	verify.AreEqual(0d, 0d);
	verify.AreEqual(0d, 0d, "AreEqual(0d, 0d) should succeed");
	verify.AreEqual(0d, 0d, "AreEqual({0}) should succeed", "0d, 0d");
	verify.AreEqual(0d, 1d, "AreEqual(0d, 1d) should fail");

	// decimal
	verify.AreEqual(0m, 0m);
	verify.AreEqual(0m, 0m, "AreEqual(0m, 0m) should succeed");
	verify.AreEqual(0m, 0m, "AreEqual({0}) should succeed", "0m, 0m");
	verify.AreEqual(0m, 1m, "AreEqual(0m, 1m) should fail");
}